package com.oba.king.hospitalinfo.doccolinformation;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;
import com.oba.king.hospitalinfo.hospitalinformation.HospitalInformation;

public class DoccolInformationBean extends BaseBean<DoccolInformation,DoccolInformationService> {

	private DBDataModel doccolInfoList = DBDataModel.create();
	private DoccolInformation doccolInfo;
	private boolean showEdit = false; 
	private String sectionName;
	private List<SelectItem> hospitalList;
	private DoccolCondition doccolConditioin;
	
	
	@Override
	public String doFind() {
		System.out.println("Start DoccolInformationBean doFind()>>>>");
		this.doccolInfoList.find(this.getService().getDao().buildAll());
		System.out.println("End DoccolInformationBean doFind()<<<<");
		return null;
	}

	@Override
	public void init() {
		System.out.println("Start DoccolInformationBean init()>>>>");
		this.doFind();
		doccolConditioin = new DoccolCondition();
		hospitalList = new ArrayList<SelectItem>();
		hospitalList.add(new SelectItem(null,"全部"));
		for (HospitalInformation hosp : getService().getDao().buildAllHospital()) {
			hospitalList.add(new SelectItem(hosp, hosp.getHospitalName()));
		}
		System.out.println("End DoccolInformationBean init()<<<<");
	}
	
	
	public void addNewDoccolInfo(){
		System.out.println("Start DoccolInformationBean addNewDoccol()>>>>");
		this.doccolInfo = new DoccolInformation();
		this.doccolInfo.setNewBo(true);
		this.showEdit = true;
		System.out.println("End DoccolInformationBean addNewDoccol()<<<<");
	}
	
	public void doEditDoccolInfo(){
		System.out.println("Start DoccolInformationBean doEditDoccol()>>>>");
		if(this.doccolInfoList.isRowAvailable()){
			this.doccolInfo = (DoccolInformation)this.doccolInfoList.getRowData();
			this.showEdit = true;
		}
		System.out.println("End DoccolInformationBean doEditDoccol()<<<<");
	}
	
	public void doDeleteDoccolInfo(){
		System.out.println("Start DoccolInformationBean doDeleteDoccol()>>>>");
		if(this.doccolInfoList.isRowAvailable()){
			this.getService().del((DoccolInformation)this.doccolInfoList.getRowData());
			this.doFind();
		}
		System.out.println("End DoccolInformationBean doDeleteDoccol()<<<<");
	}
	
	public void doSaveDetelteDoccolInfo(){
		System.out.println("Start DoccolInformationBean doSaveDetelteDoccol()>>>>");
		this.getService().save(this.doccolInfo);
		this.showEdit = false;
		this.doFind();
		System.out.println("End DoccolInformationBean doSaveDetelteDoccol()<<<<");
	}
	
//	/**
//	 * 以科室名称模糊查询
//	 * @return
//	 */
//	public void srchBySectionName(){
//		if(sectionName != null && !sectionName.trim().equals("")){
//			this.doccolInfoList.find(this.getService().getDao().srchBySectionName(sectionName),SHOW_ROW);
//		}
//	}
	
	/**
	 * 模糊查询：根据科室名称、医院和医院所属城市进行模糊查询
	 */
	public void srchByDoccolCondition(){
		System.out.println("Start DoccolInformationBean srchByDoccolCondition()>>>>");
		if(doccolConditioin != null){
			this.doccolInfoList.find(this.getService().getDao().srchByCondition(doccolConditioin));
		}
		System.out.println("Start DoccolInformationBean srchByDoccolCondition()>>>>");
	}
	
	public void cleanButton(){
		doccolConditioin  = new DoccolCondition();
//		this.doFind();
	}
	
	public boolean isShowEdit(){
		return this.showEdit;
	}
	
	public void closeShowEdit(){
		this.showEdit = false;
		this.cleanButton();
	}

	public DBDataModel getDoccolInfoList() {
		return doccolInfoList;
	}

	public void setDoccolInfoList(DBDataModel doccolInfoList) {
		this.doccolInfoList = doccolInfoList;
	}

	public DoccolInformation getDoccolInfo() {
		return doccolInfo;
	}

	public void setDoccolInfo(DoccolInformation doccolInfo) {
		this.doccolInfo = doccolInfo;
	}

	public void setShowEdit(boolean showEdit) {
		this.showEdit = showEdit;
	}

	public String getSectionName() {
		return sectionName;
	}

	public void setSectionName(String sectionName) {
		this.sectionName = sectionName;
	}

	public List<SelectItem> getHospitalList() {
		return hospitalList;
	}

	public void setHospitalList(List<SelectItem> hospitalList) {
		this.hospitalList = hospitalList;
	}
	
	public DoccolCondition getDoccolConditioin() {
		return doccolConditioin;
	}

	public void setDoccolConditioin(DoccolCondition doccolConditioin) {
		this.doccolConditioin = doccolConditioin;
	}

}
